#ifndef myevent_h__
#define myevent_h__

#include <QEvent>
#define EVENT_TYPE_DATA (QEvent::Type)(2000)
#define EVENT_TYPE_OFFLINE (QEvent::Type)(2001)
#define EVENT_TYPE_ONLINE (QEvent::Type)(2002)
#define EVENT_TYPE_REMOTE_IP (QEvent::Type)(2003)
#define EVENT_TYPE_CLOSE_TCP (QEvent::Type)(2004)
#define EVENT_TYPE_TCP_CLOSED (QEvent::Type)(2005)
#define EVENT_TYPE_LISTEN_PORT (QEvent::Type)(2006)
#define EVENT_TYPE_EXIT (QEvent::Type)(2007)
class StringEvent :public QEvent
{
	friend class DataRecv;
public:
	QString str(){ return str_; }
private:
    StringEvent(const QString& s, QEvent::Type type) :str_(s), QEvent(type){}
	QString str_;
};
class DataEvent :public QEvent
{
	friend class DataRecv;
public:
	~DataEvent(){delete[] data;}
	int timeStamp(){ return data_t; }
	int feq(){ return fq; }
	float dataAt(int idx){ return data[idx]; }
private:
	DataEvent(float* data_, QEvent::Type type_) :data(data_), QEvent(type_){}
	int fq; 
	int data_t; 
	float* data; 
};
class DataType
{
	friend class DataRecvThread;
	friend class DataRecv;
private:
 	DataType(QWidget* p, int d_size) :parent(p), data_size(d_size),
 		data_len(d_size << 2){}
	QWidget* parent;
	int data_size; 
	int data_len;
	float* getData(char* buffer)
	{
		float* d = new float[data_size];
		for (int i = 0; i < data_size; i++)
			d[i] = *(float*)(buffer + (i << 2));
		return d;
	}
};

#endif // myevent_h__
